package cn.itcast.bos.web.action;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 抽取的公共类Action
 * @author Beck
 *
 * @param <T>
 */
public class BaseAction<T> extends ActionSupport implements ModelDriven<T>{
	protected T model;

	@Override
	public T getModel() {
		return model;
	}
	
	// 当前页和每页显示多少条数据
	protected int page;
	protected int rows;
	public void setPage(int page) {
		this.page = page;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}

	// 利用构造方法来初始化model
	public BaseAction() {
		Type type = this.getClass().getGenericSuperclass();
		ParameterizedType paramType = (ParameterizedType)type;
		// 第一个参数的Class对象
		Class clz = (Class) paramType.getActualTypeArguments()[0];
		try {
			model = (T) clz.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	

}
